home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / vbcc / vbc.h < prev   
Encoding:
C/C++ Source or Header  |  1996-06-06  |  13.1 KB  |  504 lines

  1. /*  $VER: vbcc (vbc.h) V0.3     */
  2.  
  3. #include <stdlib.h>
  4. #include <limits.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stddef.h>
  8. #include <stdarg.h>
  9. #include <ctype.h>
  10.  
  11. #include "machine.h"
  12.  
  13. #define eval_constn(a) eval_const(&a->val,a->ntyp->flags)
  14.  
  15. struct function_info{
  16.     struct IC *first_ic,*last_ic;
  17.     struct Var *vars;
  18. };
  19.  
  20. struct Typ{
  21.     int flags;
  22.     struct Typ *next;
  23.     struct struct_declaration *exact;
  24.     int size;
  25. };
  26. #define TYPS sizeof(struct Typ)
  27.  
  28. #define CHAR 1
  29. #define SHORT 2
  30. #define INT 3
  31. #define LONG 4
  32. #define FLOAT 5
  33. #define DOUBLE 6
  34. #define VOID 7
  35. #define POINTER 8
  36. #define ARRAY 9
  37. #define STRUCT 10
  38. #define UNION 11
  39. #define ENUM 12
  40. #define FUNKT 13
  41. #define UNSIGNED 16
  42. #define CONST 64
  43. #define VOLATILE 128
  44. #define UNCOMPLETE 256
  45. #define STRINGCONST 512
  46.  
  47. struct identifier_list{
  48.     char *identifier;
  49.     int length;
  50.     struct identifier_list *next;
  51. };
  52. struct Var{
  53.     int storage_class,priority,flags;
  54.     char *identifier;
  55.     int nesting,offset,index;
  56.     struct Typ *vtyp;
  57.     struct const_list *clist;
  58.     struct Var *next;
  59.     struct function_info *fi;
  60.     struct Var *inline_copy;
  61. };
  62. #define USEDASSOURCE 1
  63. #define USEDASDEST 2
  64. #define DEFINED 4
  65. #define USEDASADR 8
  66. #define GENERATED 16
  67. #define CONVPARAMETER 32
  68. #define TENTATIVE 64
  69. #define USEDBEFORE 128
  70. #define INLINEV 256
  71.  
  72. #define SLSIZE 32   /*  struct_lists in diesen Abstaenden realloc'en    */
  73.  
  74. struct struct_list{
  75.     char *identifier;
  76.     struct Typ *styp;
  77.     int storage_class;
  78. };
  79. struct struct_declaration{
  80.     int count;
  81.     struct struct_declaration *next;
  82.     struct struct_list (*sl)[];
  83. };
  84.  
  85. struct struct_identifier{
  86. /*    int flags;*/
  87.     char *identifier;
  88.     struct struct_declaration *sd;
  89.     struct struct_identifier *next;
  90. };
  91.  
  92. struct obj{
  93.     int flags,reg;
  94.     struct Var *v;
  95.     struct AddressingMode *am;
  96.     union atyps{
  97.         zchar vchar;
  98.         zuchar vuchar;
  99.         zshort vshort;
  100.         zushort vushort;
  101.         zint vint;
  102.         zuint vuint;
  103.         zlong vlong;
  104.         zulong vulong;
  105.         zfloat vfloat;
  106.         zdouble vdouble;
  107.         zpointer vpointer;
  108.     }val;
  109. };
  110.  
  111. struct node{
  112.     int flags,lvalue,sidefx;
  113.     struct Typ *ntyp;
  114.     struct node *left;
  115.     struct node *right;
  116.     struct argument_list *alist;
  117.     char *identifier;
  118.     union atyps val;
  119.     struct obj o;
  120. /*  es muss noch sowas wie struct internal_object * dazu    */
  121. };
  122.  
  123. typedef struct node *np;
  124.  
  125. #define NODES sizeof(struct node)
  126.  
  127. #define KOMMA 1
  128. #define ASSIGN 2
  129. #define ASSIGNADD 3
  130. #define ASSIGNSUB 4
  131. #define ASSIGNMULT 5
  132. #define ASSIGNDIV 6
  133. #define ASSIGNMOD 7
  134. #define ASSIGNAND 8
  135. #define ASSIGNXOR 9
  136. #define ASSIGNOR 10
  137. #define ASSIGNLSHIFT 11
  138. #define ASSIGNRSHIFT 12
  139. #define COND 13
  140. #define LOR 14
  141. #define LAND 15
  142. #define OR 16
  143. #define XOR 17
  144. #define AND 18
  145. #define EQUAL 19
  146. #define INEQUAL 20
  147. #define LESS 21
  148. #define LESSEQ 22
  149. #define GREATER 23
  150. #define GREATEREQ 24
  151. #define LSHIFT 25
  152. #define RSHIFT 26
  153. #define ADD 27
  154. #define SUB 28
  155. #define MULT 29
  156. #define DIV 30
  157. #define MOD 31
  158. #define NEGATION 32
  159. #define KOMPLEMENT 33
  160. #define PREINC 34
  161. #define POSTINC 35
  162. #define PREDEC 36
  163. #define POSTDEC 37
  164. #define MINUS 38
  165. #define CONTENT 39
  166. #define ADDRESS 40
  167. #define CAST 41
  168. #define CALL 42
  169. #define INDEX 43
  170. #define DPSTRUCT 44
  171. #define DSTRUCT 45
  172. #define IDENTIFIER 46
  173. #define CEXPR 47
  174. #define STRING 48
  175. #define MEMBER 49
  176. #define CONVCHAR 50
  177. #define CONVSHORT 51
  178. #define CONVINT 52
  179. #define CONVLONG 53
  180. #define CONVFLOAT 54
  181. #define CONVDOUBLE 55
  182. #define CONVVOID 56
  183. #define CONVPOINTER 57
  184. #define CONVUCHAR 58
  185. #define CONVUSHORT 59
  186. #define CONVUINT 60
  187. #define CONVULONG 61
  188. #define ADDRESSA 62
  189. #define FIRSTELEMENT 63
  190. #define PMULT 64
  191. #define ALLOCREG 65
  192. #define FREEREG 66
  193. #define PCEXPR 67
  194. #define TEST 68
  195. #define LABEL 69
  196. #define BEQ 70
  197. #define BNE 71
  198. #define BLT 72
  199. #define BGE 73
  200. #define BLE 74
  201. #define BGT 75
  202. #define BRA 76
  203. #define COMPARE 77
  204. #define PUSH 78
  205. #define POP 79
  206. #define ADDRESSS 80
  207. #define ADDI2P 81
  208. #define SUBIFP 82
  209. #define SUBPFP 83
  210. #define PUSHREG 84
  211. #define POPREG 85
  212. #define POPARGS 86
  213. #define SAVEREGS 87
  214. #define RESTOREREGS 88
  215. #define ILABEL 89
  216. #define DC 90
  217. #define ALIGN 91
  218. #define COLON 92
  219. #define GETRETURN 93
  220. #define SETRETURN 94
  221. #define MOVEFROMREG 95
  222. #define MOVETOREG 96
  223. #define NOP 97
  224.  
  225. struct argument_list{
  226.     np  arg;
  227.     struct argument_list *next;
  228. };
  229.  
  230. #define AUTO 1
  231. #define REGISTER 2
  232. #define STATIC 3
  233. #define EXTERN  4
  234. #define TYPEDEF 5
  235.  
  236. #define MAXI 100 /* maximale Laenge von Identifiers in Bytes    */
  237. #define MAXINPUT 2000    /* maximale Laenge einer Eingabezeile in Bytes  */
  238. #define MAXN 30 /* maximale Verschachtelung von Bloecken */
  239. #define MAXM 100 /* maximale Anzahl an Bloecken pro Funktion (grob) */
  240.  
  241. #define arith(c) ((c)>=CHAR&&(c)<=DOUBLE)
  242.  
  243. extern char *typname[];
  244. extern int sizetab[];
  245. extern char *storage_class_name[];
  246. extern char *ename[];
  247.  
  248. /* Tabelle fuer alignment requirements, maschinenabhaengig */
  249. extern int align[],maxalign;
  250.  
  251. extern void error(int,...);
  252.  
  253. #define ierror(a) error(158,(a),__LINE__,__FILE__)
  254.  
  255. extern void free_fi(struct function_info *);
  256. extern struct Typ *arith_typ(struct Typ*,struct Typ *);
  257. extern void insert_const(np);
  258. extern void insert_const2(union atyps *,int);
  259. extern int int_erw(int);
  260. extern int type_expression(np),compare_pointers(struct Typ *,struct Typ *,int),
  261.     compare_sd(struct struct_declaration *,struct struct_declaration *);
  262. extern np identifier_expression(void),constant_expression(void),string_expression(void),
  263.    postfix_expression(void),unary_expression(void),cast_expression(void),
  264.    multiplicative_expression(void),additive_expression(void),
  265.    shift_expression(void),relational_expression(void),equality_expression(void),
  266.    and_expression(void),exclusive_or_expression(void),
  267.    inclusive_or_expression(void),logical_and_expression(void),
  268.    logical_or_expression(void),conditional_expression(void),
  269.    assignment_expression(void),expression(void),primary_expression(void);
  270. /* puh  */
  271. extern void pre(FILE *,np),pra(FILE *,struct argument_list *);
  272. extern void free_expression(np),free_alist(struct argument_list *);
  273. extern void prd(FILE *,struct Typ *),freetyp(struct Typ *),cpbez(char *m),cpnum(char *m),killsp(void);
  274. extern struct struct_declaration *add_sd(struct struct_declaration *);
  275. extern void add_sl(struct struct_declaration *,struct struct_list (*)[]);
  276. extern void free_sd(struct struct_declaration *);
  277. extern void prl(FILE *,struct struct_declaration *);
  278. extern char *add_identifier(char *,int);
  279. extern struct Typ *declarator(struct Typ *),*direct_declarator(struct Typ *),
  280.            *pointer(struct Typ *),*declaration_specifiers(void),
  281.            *clone_typ(struct Typ *);
  282. extern int declaration(int),type_uncomplete(struct Typ *);
  283. extern struct struct_declaration *find_struct(char *,int);
  284. extern void add_struct_identifier(char *,struct struct_declaration *);
  285. extern void free_si(struct struct_identifier *);
  286. extern char *s,*ident;
  287. extern char string[MAXINPUT+2],number[MAXI],buff[MAXI];
  288. extern struct struct_declaration *first_sd[MAXN],*last_sd[MAXN],*merk_sdf,*merk_sdl;
  289. extern struct struct_identifier *first_si[MAXN],*last_si[MAXN],*merk_sif,*merk_sil;
  290. extern struct identifier_list *first_ilist[MAXN],*last_ilist[MAXN],*merk_ilistf,*merk_ilistl;
  291. extern void free_ilist(struct identifier_list *);
  292. extern int nesting;
  293. extern char *empty;
  294. extern struct Var *first_var[MAXN],*last_var[MAXN],*merk_varf,*merk_varl;
  295. extern struct Var *add_var(char *,struct Typ *,int,struct const_list *);
  296. extern void free_var(struct Var *);
  297. extern void var_declaration(void);
  298. extern int storage_class_specifiers(void);
  299. extern void enter_block(void),leave_block(void);
  300. extern struct Var *find_var(char *,int);
  301. extern int szof(struct Typ *);
  302.  
  303. extern void eval_const(union atyps *,int);
  304. extern zchar vchar; extern zuchar vuchar;
  305. extern zshort vshort; extern zushort vushort;
  306. extern zint vint; extern zuint vuint;
  307. extern zlong vlong; extern zulong vulong;
  308. extern zfloat vfloat; extern zdouble vdouble;
  309. extern zpointer vpointer;
  310. extern zchar vchar2; extern zuchar vuchar2;
  311. extern zshort vshort2; extern zushort vushort2;
  312. extern zint vint2; extern zuint vuint2;
  313. extern zlong vlong2; extern zulong vulong2;
  314. extern zfloat vfloat2; extern zdouble vdouble2;
  315. extern zpointer vpointer2;
  316.  
  317. extern int usz;
  318.  
  319. extern int DEBUG,MDEBUG;
  320.  
  321. struct IC{
  322.     struct IC *prev,*next;
  323.     int code,typf,defindex,expindex,copyindex;
  324.     struct obj q1,q2,z;
  325. };
  326.  
  327. #define ICS sizeof(struct IC)
  328. #define KONST 1     /*  KONST muss immer am kleinsten sein, um beim swappen */
  329.                     /*  fuer available_expressions und Konstanten nach      */
  330.                     /*  rechts nicht in eine Endlosschleife zu kommen       */
  331. #define VAR 2
  332. #define SCRATCH 8
  333. #define STACK 16
  334. #define DREFOBJ 32
  335. #define REG 64
  336. #define VARADR 128
  337. #define DONTREGISTERIZE 256
  338.  
  339. extern struct IC *first_ic,*last_ic;
  340. extern int regs[MAXR+1],regsa[MAXR+1],regused[MAXR+1],regscratch[MAXR+1],regsize[MAXR+1];
  341. extern struct Var *regsv[MAXR+1],*regsbuf[MAXR+1];
  342. extern int regbnesting[MAXR+1];
  343.  
  344. extern void add_IC(struct IC *),free_IC(struct IC *),insert_IC(struct IC *,struct IC *);
  345. extern void gen_IC(np,int,int),convert(np,int),gen_label(int),savescratch(int,struct IC *,int);
  346. extern int push_args(struct argument_list *,struct struct_declaration *,int);
  347. extern int regok(int,int,int),allocreg(int,int),freturn(struct Typ *);
  348. extern int icok(struct IC *);
  349. extern void free_reg(int);
  350. extern void pric(FILE *,struct IC *),pric2(FILE *,struct IC *);
  351. extern char *regnames[];
  352. extern void probj(FILE *,struct obj *,int,int);
  353.  
  354. extern void printzl(FILE *,zlong),printzul(FILE *,zulong),printzd(FILE *,zdouble);
  355. extern void printval(FILE *,union atyps *,int,int);
  356.  
  357. extern int label;
  358.  
  359. extern FILE *out,*ic1,*ic2,*ppout;
  360.  
  361. extern void statement(void),labeled_statement(void),if_statement(void);
  362. extern void switch_statement(void),while_statement(void),for_statement(void);
  363. extern void do_statement(void),goto_statement(void),continue_statement(void);
  364. extern void break_statement(void),return_statement(void);
  365. extern void expression_statement(void),compound_statement(void),raus(void);
  366. extern void translation_unit(void);
  367. extern int main(int, char *[]);
  368. extern int nocode,registerpri,looppri,currentpri;
  369.  
  370. extern void *mymalloc(size_t);
  371.  
  372. extern np makepointer(np);
  373.  
  374. extern int must_convert(np,int);
  375.  
  376. extern int switch_typ,switch_count,switch_act;
  377. struct llist{
  378.     char *identifier;
  379.     int label,flags,switch_count;
  380.     struct llist *next;
  381.     union atyps val;
  382. };
  383. #define LABELDEFINED 1
  384. #define LABELUSED 2
  385. #define LABELDEFAULT 4
  386. #define LSIZE sizeof(struct llist)
  387. extern struct llist *first_llist,*last_llist;
  388. extern struct llist *find_label(char *),*add_label(char *);
  389. extern void free_llist(struct llist *);
  390.  
  391. extern int endok,return_label,return_value,break_label;
  392. extern struct Var *return_var;
  393. extern struct Typ *return_typ;
  394. extern int local_offset[MAXN];
  395.  
  396. extern void scratch_var(struct obj *,int),get_scratch(struct obj *,int,int);
  397. extern struct obj gen_cond(int,int,int);
  398.  
  399. extern void simple_regs(void);
  400.  
  401. union ppi {char *p;long l;void (*f)(char *);};
  402.  
  403. #define USEDFLAG 1
  404. #define STRINGFLAG 2
  405. #define VALFLAG 4
  406. #define FUNCFLAG 8
  407.  
  408. #define MAXCF 30
  409. extern int c_flags[MAXCF];
  410. extern char *c_flags_name[MAXCF];
  411. extern union ppi c_flags_val[MAXCF];
  412.  
  413. extern int g_flags[MAXGF];
  414. extern char *g_flags_name[MAXGF];
  415. extern union ppi g_flags_val[MAXGF];
  416.  
  417.  
  418. extern FILE *open_out(char *,char *);
  419.  
  420. extern char *inname;
  421.  
  422. extern void gen_code(FILE *,struct IC *,struct Var *,int);
  423.  
  424. extern int init_cg(void);
  425.  
  426. extern void gen_vars(struct Var *);
  427.  
  428. extern int max_offset;
  429.  
  430. extern int function_calls;
  431.  
  432. struct const_list{
  433.     union atyps val;
  434.     np tree;
  435.     struct const_list *other,*next;
  436. };
  437. extern struct const_list *first_clist,*last_clist;
  438. #define CLS sizeof(struct const_list)
  439.  
  440. /*  Format der Tabelle fuer Fehlermeldungen */
  441. struct err_out{
  442.     char *text;
  443.     int  flags;
  444. };
  445. /*  Flags fuer err_out.flags    */
  446. #define ERROR       1
  447. #define WARNING     2
  448. #define ANSIV       4
  449. #define INTERNAL    8
  450. #define FATAL      16
  451. #define MESSAGE    32
  452. #define DONTWARN   64
  453. #define PREPROC   128
  454.  
  455. extern struct err_out err_out[];
  456. extern int err_num;
  457.  
  458. extern void gen_dc(FILE *,int,struct const_list *);
  459. extern void gen_ds(FILE *,int,struct Typ *),gen_var_head(FILE *,struct Var *);
  460. extern void gen_align(FILE *,int);
  461. extern void free_clist(struct const_list *);
  462.  
  463. extern void remove_IC(struct IC *);
  464.  
  465. extern zlong t_min[];
  466. extern zulong t_max[];
  467.  
  468. extern int afterlabel;
  469.  
  470. extern int goto_used;
  471.  
  472. extern int errors;
  473. extern int ic_count;
  474.  
  475.  
  476. /*  fuer den Praeprozessor  */
  477.  
  478. #define MAXPPINPUT 2000     /*  maximale Laenge einer Eingabezeile  */
  479. #define MAXINCNESTING 50    /*  maximale Verschachtelung von Includes   */
  480.  
  481. extern FILE *in[MAXINCNESTING];    /*  Sourcefiles     */
  482. extern int zn[MAXINCNESTING];      /*  Zeilennummern   */
  483. extern char *filename[MAXINCNESTING];   /*  Filenamen   */
  484. extern int incnesting;             /*  aktuelle Verschachtelungstiefe  */
  485. extern unsigned long linenr;                 /*  Zeilennummer */
  486.  
  487. #define MAXINCPATHS 20      /*  maximale Anzahl der Includepfade    */
  488.  
  489. extern char *incpath[MAXINCPATHS];   /*  Includepfade    */
  490.                                             /*  Rest ist NULL   */
  491.  
  492. extern int incpathc;     /*  Anzahl der Includepfade     */
  493.  
  494. int pp_init(void);
  495. void pp_free(void);
  496. int pp_include(char *filename);
  497. int pp_nextline(void);
  498. int pp_define(char *text);
  499.  
  500. int only_inline;
  501.  
  502. int read_new_line;
  503.  
  504.